package oop.ex3.serverprotocol;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import oop.ex3.nameserver.NameServer;
import oop.ex3.sharedclasses.IPaddress;

/**
 * Handles DONTCONTAINFILE Message.
 * handles a client's request to update the NameServer of removing a file.
 * 
 * @author zablo
 *
 */
public class DontContainFile extends ClientMessageHandler {

	@Override
	public boolean run(NameServer server,  IPaddress sessionIP,
			DataInputStream clientInput, DataOutputStream clientOutput) {
		try {
			String fileName = clientInput.readUTF();
			if (endsWithEnd(clientInput)==FAILURE){
				return FAILURE;
			}
			
			if (ServerMessageSender.done(clientOutput)==FAILURE){
				return FAILURE;
			}
			
			server.removeFile(sessionIP, fileName);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return FAILURE;
		}
		return SUCCESS;
	}

}
